﻿using PureMVC.Patterns.Mediator;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Rzc.DevPlat.View
{
    public class HeaderMenuMediator : Mediator
    {
        Sunny.UI.UINavBar Header;
        public HeaderMenuMediator(object viewCommviewComponent) : base("HeaderMenuMediator", viewCommviewComponent)
        {
            Header = viewCommviewComponent as Sunny.UI.UINavBar;
            Header.MenuItemClick += Header_MenuItemClick;
        }
        void CreateMenuItems()
        {
            System.Windows.Forms.TreeNode treeNodeScane = new System.Windows.Forms.TreeNode("管网浏览");
            System.Windows.Forms.TreeNode treeNodeSearch = new System.Windows.Forms.TreeNode("管网查询");
            System.Windows.Forms.TreeNode treeNodeEdit = new System.Windows.Forms.TreeNode("管网编辑");
            System.Windows.Forms.TreeNode treeNodeAnalysis = new System.Windows.Forms.TreeNode("综合分析");
            System.Windows.Forms.TreeNode treeNodeTheme = new System.Windows.Forms.TreeNode("系统主题");
            Header.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
            treeNodeScane,
            treeNodeSearch,
            treeNodeEdit,
            treeNodeAnalysis,
            treeNodeTheme});

            var styles = UIStyles.PopularStyles();
            foreach (UIStyle style in styles)
            {
                Header.CreateChildNode(treeNodeTheme, style.DisplayText(), style.Value());
            }
            AddMapOperaterMenuItem(Header, treeNodeScane);
            //工作空间菜单
            void AddMapOperaterMenuItem(UINavBar uiNavBar, TreeNode parentNode)
            {
                uiNavBar.CreateChildNode(parentNode, "打开工作空间", 10001);
                uiNavBar.CreateChildNode(parentNode, "关闭工作空间", 10002);
                uiNavBar.CreateChildNode(parentNode, "保存工作空间", 10003);
                uiNavBar.CreateChildNode(parentNode, "另存工作空间", 10004);
            }
        }
        private void Header_MenuItemClick(string itemText, int menuIndex, int pageIndex)
        {
            if (menuIndex == 4)
            {
                SendNotification("SetStyleManager", (Sunny.UI.UIStyle)pageIndex);
            }
            else if (menuIndex == 0)
            {
                if (pageIndex == 10001)
                {
                    SendNotification("OpenWorkSpaceCommand");
                }
                else if (pageIndex == 10002)
                {
                    SendNotification("CloseWorkSpaceCommand");
                }
                else if (pageIndex == 10003)
                {
                    SendNotification("SaveWorkSpaceCommand");
                }
                else if (pageIndex == 10004)
                {
                    SendNotification("SaveAsWorkSpaceCommand");
                }
            }
        }
    }
}
